<?php

class Admin_Model_Categories extends Zend_Db_Table_Abstract
{
    protected $_name = 'categories';
    public function getAllData(){
        $query = $this->select()
                        ->from($this->_name)
                        ->order('ord DESC')
                        ->order('catId ASC');
        return $this->fetchAll($query);
    }
    public function getParentIdData($parentId){
        $query = $this->select()
                        ->from($this->_name)
                        ->where('parentId = ?', $parentId)
                        ->order('ord DESC')
                        ->order('catId ASC');
        return $this->fetchAll($query);
    }
    public function addData($catId, $catName, $parentId, $ord, $status){
    	$data = array('catId' => $catId, 
                    'catName' => $catName, 
                    'parentId' => $parentId, 
                    'ord' => $ord, 
                    'status' => $status);
        $idAdd = $this->insert($data);
        return $idAdd;
    }
    public function deleteData($catId){
        $this->delete('catId = "' . $catId.'"');
    }
    public function updateData($catId, $catName, $parentId, $ord, $status){
    	$data = array('catName' => $catName, 
                    'parentId' => $parentId, 
                    'ord' => $ord, 
                    'status' => $status);
        return $this->update($data, 'catId = "' . $catId.'"');
    }
    public function getDataById($catId){
    	$query = $this->select()
                        ->from($this->_name)
                        ->where('catId = ?',$catId);
        return $this->fetchRow($query);
    }
    public function getCategories()
    {
        $sql = "CALL GetHierarchyCategories()";
        $categories = $this->getDefaultAdapter()->query($sql);
        $stmt = $categories->fetchAll(PDO::FETCH_OBJ);
        return $stmt;
    }
}

























